<?php

/*
  VoIP Wholesale 1.0
  ------------------
  Document   : app_mod_cron
  Created on : Jan 02, 2012, 1:49:21 PM
  Author     : Milos Jovanovic <miloscode@gmail.com>
  Description:

 */
class App_mod_cron extends MY_Model {
    
    function __construct() {
        parent::__construct();

		$this->MODULE->config->load('module_config');	
		$this->MODULE->short_name = $this->MODULE->config->item('short_name');
		$this->MODULE->settings_table = $this->MODULE->config->item('settings_table');	 		
    }

public function update_final_routing_statuses()
{
	
	/* *********************************************************************
	 * FINAL TABLE FOR RELATIONS BETWEEN ORIGIN AND TERMINATION TRUNKS
	 * *********************************************************************/
	$query = $this->db->order_by('id','DESC')->get('relations_origin_termination');
	foreach($query -> result_array() as $entry)
	{
		unset($update);		
		if($entry['termination_carrier_status'] == 1 && $entry['termination_trunk_status'] == 1 && $entry['allowed'] == 1)
		{
			$update['status'] = 1;
		}
		else
		{
			$update['status'] = 0;
		}		
		$this->db->where('id',$entry['id'])->update('relations_origin_termination',$update);
	}
	
	/* *********************************************************************
	 * ORIGIN TRUNKS TABLE
	 * *********************************************************************/
	$query = $this->db->order_by('id','DESC')->get('origin_trunks');
	foreach($query -> result_array() as $entry)
	{
		unset($update);		
		if($entry['carrier_status'] == 1 && $entry['trunk_status'] == 1)
		{
			$update['status'] = 1;
		}
		else
		{
			$update['status'] = 0;
		}		
		$this->db->where('id',$entry['id'])->update('origin_trunks',$update);
	}

	/* *********************************************************************
	 * TERMINATION TRUNKS TABLE
	 * *********************************************************************/
	$query = $this->db->order_by('id','DESC')->get('termination_trunks');
	foreach($query -> result_array() as $entry)
	{
		unset($update);		
		if($entry['carrier_status'] == 1 && $entry['trunk_status'] == 1)
		{
			$update['status'] = 1;
		}
		else
		{
			$update['status'] = 0;
		}		
		$this->db->where('id',$entry['id'])->update('termination_trunks',$update);
	}
	
	return true;
}
	
}
?>
	